#include <iostream>
#include <fstream>

#include "run_test.h"

#include "function.h"
#include "ZFunction.h"
#include "griewank_function.h"
#include "modifiedgriewank_function.h"
#include "rosenbrock_function.h"
#include "shekel_function.h"
#include "zakharov_function.h"
#include "B2_function.h"
#include "nr_c/nr.h"

void test_CTS(int argc, char *argv[ ])
{
  char FileFamot1[80];      // used for ZFunction only
  char FileFamot2[80];      // used for ZFunction only
  int seed;                 // seed for random number
  int numNeighPoint;        // number of neighbouring solutions
  double radiusTabuSphere;  // radius of the tabu hypersphere
  double radiusPromSphere;  // radius of the promising hypersphere
  double biggestRadius;     // radius of the biggest hypersphere
  int maxTabuListSize;      // size of the tabu list
  int maxPromlistSize;      // size of the promising list
  int numRun;               // number of runs
  int numDim;	              // the number of dimensions
  int maxIteration;         // max number of iterations



  /////////////////////////////////////////////////////
  // Get input parameters
  /////////////////////////////////////////////////////

  if (argc == 13)
  {
    // required content of input arguments
    seed = atoi(argv[1]);
    numNeighPoint = atoi(argv[2]);
    radiusTabuSphere = atof(argv[3]);
    radiusPromSphere = atof(argv[4]);
    biggestRadius = atof(argv[5]);    
    maxTabuListSize = atoi(argv[6]);
    maxPromlistSize = atoi(argv[7]);
    numRun = atoi(argv[8]);
    numDim = atoi(argv[9]);
    maxIteration = atoi(argv[10]);
    strcpy_s(FileFamot1, 80, argv[11]);
    strcpy_s(FileFamot2, 80, argv[12]);
  }
  else if (argc == 1)  // if no arguments given to executable do this
  {
    ifstream file("input/params_cts.txt");

    if (! file)
    {
      cout << "Cannot open params.in\n";
      exit(1);
    }

    file >> seed >> numNeighPoint >> radiusTabuSphere >> radiusPromSphere
      >> biggestRadius >> maxTabuListSize >> maxPromlistSize >> numRun
      >> numDim >> maxIteration >> FileFamot1 >> FileFamot2;

    file.close();
  }
  else
  {
    cout << "Incorrect input.\n";
    exit(1);
  }

  //Function *modgrie = new ModGriewankFunction(numDim, 10.0);
  Function *ZFuncFamot = new ZFunction(numDim, FileFamot1, FileFamot2);
  //Function *grieFunc = new GriewankFunction(numDim);
  //Function *rosenFunc = new RosenbrockFunction(numDim);
  //Function *shekelFunc = new ShekelFunction(numDim);
  //Function *zakFunc = new ZakharovFunction(numDim);
  //Function *b2Func = new B2Function(numDim);

  cout << "-------------------" << endl
       << "|       CTS       |" << endl
       << "-------------------" << endl;
  cout << "Dimension: " << numDim << endl 
    << "Total number of runs: " << numRun << endl << endl;

  //run_CTS(argc, argv, modgrie, string("output/Griewank/Mod/"));
  run_CTS(argc, argv, ZFuncFamot, string("output/ZfuncMolecule/Famot/CTS/"));
  //run_CTS(argc, argv, grieFunc, string("output/Griewank/"));
  //run_CTS(argc, argv, rosenFunc, string("output/Rosenbrock/"));
  //run_CTS(argc, argv, shekelFunc, string("output/Shekel/"));
  //run_CTS(argc, argv, zakFunc, string("output/Zakharov/"));
  //run_CTS(argc, argv, b2Func, string("output/B2/"));
}